package com.card.game;

import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import org.jboss.netty.channel.ChannelHandlerContext;

import com.card.admin.pojo.Admin;
import com.card.admin.pojo.AdminManager;
import com.card.common.CardContants;
import com.card.common.MessageComm;
import com.card.game.BasePlayer.UserState;
import com.card.game.ddz.DdzPlayer;
import com.card.game.ddz.DdzRoom;
import com.card.game.dn.NnPlayer;
import com.card.game.dn.NnRoom;
import com.card.game.event.EventType;
import com.card.game.pdk.PdkPlayer;
import com.card.game.pdk.PdkRoom;
import com.card.game.room.AbstractRoom;
import com.card.game.room.DateUtils;
import com.card.game.room.RoomManager;
import com.card.game.room.RoomSetting;
import com.card.game.room.RoomSetting.RoomMode;
import com.card.game.room.RoomState;
import com.card.game.room.SHRoom;
import com.card.game.room.TggRoom;
import com.card.game.room.record.Ddz;
import com.card.game.room.record.GamePlayer;
import com.card.game.room.record.Mj;
import com.card.game.room.record.Nn;
import com.card.game.room.record.Pdk;
import com.card.game.room.record.RoomRecord;
import com.card.game.room.record.Zjh;
import com.card.match.IMatchRoom;
import com.card.message.JsonMessageCenter;
import com.card.user.StringParam;
import com.card.user.User;
import com.card.user.UserUtils;
import com.card.user.UserCurrency.CurrencyKind;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.xiaoao.net.db.DBManager;
import com.xiaoao.net.db.Entity;
import com.xiaoao.net.db.mongo.MongodbManager;
import com.xiaoao.net.global.Global;
import com.xiaoao.net.json.IMsgProcesser;
import com.xiaoao.net.json.Router;
import com.xiaoao.net.json.message.JsonMessage;
import com.xiaoao.net.utils.PrimaryKey;
import com.xiaoao.net.utils.StringUtil;
import com.xiaoao.net.utils.json.JSONUtils;

public class RoomLogic implements IMsgProcesser {
	private static final RoomLogic instance = new RoomLogic();

	public static RoomLogic getInstance() {
		return instance;
	}

	@Override
	public void registMsgId() {
		Router.getInstance().registMsg(MessageComm.C2S_RoomCreate, this);
		// 代开房间
		Router.getInstance().registMsg(MessageComm.C2S_RoomAgentCreate, this);
		// 代开房间与代开房历史记录列表
		Router.getInstance().registMsg(MessageComm.C2S_Room_List, this);
		Router.getInstance().registMsg(MessageComm.C2S_HistoryRoom_List, this);
		// gpgp
		Router.getInstance().registMsg(MessageComm.C2S_JoinGonghui, this);// 展示工会
		Router.getInstance().registMsg(MessageComm.C2S_JoinGonghuiRoom, this);// 进入工会游戏房间2
		// gp
		Router.getInstance().registMsg(MessageComm.C2S_RoomJoin, this);
		Router.getInstance().registMsg(MessageComm.C2S_DiaoXianRoomDisband, this);
		Router.getInstance().registMsg(MessageComm.C2S_RoomDisbandReply, this);
		Router.getInstance().registMsg(MessageComm.C2S_RoomDisbandRequest, this);
		Router.getInstance().registMsg(MessageComm.C2S_DisbandAgencyCreateRoom, this);
		Router.getInstance().registMsg(MessageComm.C2S_StartTgg, this);
		Router.getInstance().registMsg(MessageComm.C2S_Ready, this);
		Router.getInstance().registMsg(MessageComm.C2S_Test,this);//测试
	}

	// 程序执行选项
	@Override
	public void doProcess(int msgId, JsonMessage serverMsg, ChannelHandlerContext ctx) {
		switch (msgId) {
		case MessageComm.C2S_RoomCreate:
			createRoom(serverMsg, ctx);
			break;
		// 代开房间
		case MessageComm.C2S_RoomAgentCreate:
			createAgentRoom(serverMsg, ctx);
			break;
		// 工会房间列表
		case MessageComm.C2S_JoinGonghui:
			//getGonghuiInfo(serverMsg, ctx);
			break;
		// 进入工会房间
		case MessageComm.C2S_JoinGonghuiRoom:
			//joinGonghuiRoom(serverMsg, ctx);
			break;
		// 列表方法
		case MessageComm.C2S_Room_List:
			RoomList(serverMsg, ctx);
			break;
		// 历史列表
		case MessageComm.C2S_HistoryRoom_List:
			HistoryRoomList(serverMsg, ctx);
			break;
		case MessageComm.C2S_RoomJoin:
			joinRoom(serverMsg, ctx);
			break;
		case MessageComm.C2S_Ready:
			userReady(serverMsg, ctx);
			break;
		case MessageComm.C2S_DiaoXianRoomDisband:
			dxRoomDisband(serverMsg, ctx);
			break;
		// case MessageComm.C2S_RoomDisband:
		// disbandRoom(serverMsg, ctx);
		// break;
		case MessageComm.C2S_RoomDisbandRequest:
			disbandRoomRequest(serverMsg, ctx);
			break;
		case MessageComm.C2S_DisbandAgencyCreateRoom:
			disbandAgencyCreateRoom(serverMsg, ctx);
			break;
		case MessageComm.C2S_StartTgg:
			// startTgg(serverMsg, ctx);
			break;
		case MessageComm.C2S_RoomDisbandReply:
			disbandRoomReply(serverMsg, ctx);
			break;
		case MessageComm.C2S_Test:
			test(serverMsg, ctx);
			break;
		}
	}
	//测试
	private void test(JsonMessage serverMsg, ChannelHandlerContext ctx)
	{
		User user = (User) ctx.getAttachment();
		int a=serverMsg.getAsInt("testint");
		System.out.println(a);
		
		 String s = Integer.toString(a);
		JsonMessageCenter.getInstance().sendEorrorMessage(user ,"测试测试" );
	}

	// 创建房间
	private void createRoom(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		ReentrantLock lock = user.getLock();
		try {
			lock.lock();
			if (user.getRoom() != null) {
				Global.logErrorMessage("不能重复创建！！！！！");
			} else {
				// 从client端传递roomType过来，判断房间类型，进而创建房间（在此处可以进行代开房间的逻辑的添加）
				int roomType = serverMsg.getAsInt("roomType");
				if (roomType == CardContants.GAMETYPE_SH) {
					createShRoom(user, serverMsg, false);
				} else if (roomType == CardContants.GAMETYPE_TGG) {
					createTGGRoom(user, serverMsg, false);
				} else if (roomType == CardContants.GAMETYPE_Ddz) {
					createDdzRoom(user, serverMsg, false);
				} else if (roomType == CardContants.GAMETYPE_Pdk) {
					createPdkRoom(user, serverMsg, false);
				} else if (roomType == CardContants.GAMETYPE_Nn) {
					createNnRoom(user, serverMsg, false);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
		// 将user对象的数据，以及创建的房间的信息 保存，留待后面调用
		// return ReturnMsgCode;
	}

	// 代开房间（只有开房的人才能解散房间）
	private void createAgentRoom(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		System.out.println("=====代开房间" + user.getUsername());
		try {
			System.out.println("====================代开房间");
			// 直接显示开房信息，不作任何操作（后续操作与createRoom时所调用的功能相同）
			RoomSetting roomSetting = new RoomSetting();
			if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
				JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
				// AgencyCreateRoomReturnMsgCode = 0;
			} else {
				// JsonMessageCenter.getInstance().sendEorrorMessage(user,
				// "房间代开成功");
				// 从client端传递roomType过来，判断房间类型，进而创建房间
				int roomType = serverMsg.getAsInt("roomType");
				if (roomType == CardContants.GAMETYPE_SH) {
					createShRoom(user, serverMsg, true);
				} else if (roomType == CardContants.GAMETYPE_TGG) {
					createTGGRoom(user, serverMsg, true);
				} else if (roomType == CardContants.GAMETYPE_Ddz) {
					createDdzRoom(user, serverMsg, true);
				} else if (roomType == CardContants.GAMETYPE_Pdk) {
					createPdkRoom(user, serverMsg, true);
				} else if (roomType == CardContants.GAMETYPE_Nn) {
					createNnRoom(user, serverMsg, true);
				}
				JsonMessage message = new JsonMessage(MessageComm.S2C_RoomAgentCreate);
				message.addProperty("msg", "房间代开成功");
				JsonMessageCenter.getInstance().sendMessage(message, user);
				// AgencyCreateRoomReturnMsgCode = 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "程序异常");
			// AgencyCreateRoomReturnMsgCode = -1;

		}
		// return AgencyCreateRoomReturnMsgCode;
	}

	// 工会房间列表
	/*private void GonghuiList(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		System.out.println(user.getUsername() + "," + user.getPrimaryKey());
		Admin admin = AdminManager.getAdmin(user.getPrimaryKey());
		if (admin == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "你还没有加入工会!");
			return;
		}
		String fatherName = admin.getFatherName();
		User father;
		if ("admin".equals(fatherName)) {
			father = user;
			System.out.println("自己的工会");
		} else {
			father = UserUtils.getUserByPrimaryKey(fatherName);
		}
		System.out.println("fatherName" + fatherName);

		System.out.println("===获取工会房间信息");

		int roomId = getARoom(father);

		if (roomId == 0) {
			roomId = createGonghuiRoom(father, true);
		}
		AbstractRoom room = RoomManager.getInstance().getRoomById(roomId);
		if (room.getRoomType() == CardContants.GAMETYPE_SH) {
			com.card.game.Player player = new com.card.game.Player(user);
			if (room.getPlayerList().size() < 1) {
				SHRoom shRoom = (SHRoom) room;
				shRoom.changeZhuang(player.getUserId());
			}
			room.addPlayer(player);
		}
	}*/

	// 工会房间详情信息
	/*private void getGonghuiInfo(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		System.out.println(user.getUsername() + "," + user.getPrimaryKey());
		Admin admin = AdminManager.getAdmin(user.getPrimaryKey());
		if (admin == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "你还没有加入工会!");
			return;
		}

		//String roomsettings = admin.getRoomSettings();
		System.out.println("工会房间设置" + roomsettings);
		String gonghuiname = roomsettings.split(",")[0];
		String gonghuiname1 = roomsettings.split(",")[1];
		String gonghuiname2 = roomsettings.split(",")[2];
		String gonghuiname3 = roomsettings.split(",")[3];
		String gonghuiname4 = roomsettings.split(",")[4];
		String gonghuiname5 = roomsettings.split(",")[5];
		String gonghuiname6 = roomsettings.split(",")[6];

		String fatherName = admin.getFatherName();
		User father;
		if ("admin".equals(fatherName)) {
			father = user;
			System.out.println("自己的工会");
		} else {
			father = UserUtils.getUserByPrimaryKey(fatherName);
		}
		System.out.println("fatherName" + gonghuiname1);
		System.out.println("fatherName" + gonghuiname2);
		System.out.println("fatherName" + gonghuiname3);
		System.out.println("fatherName" + gonghuiname4);

		System.out.println("===获取工会房间信息");

		// 获取可用的房间号
		int roomId = getARoom(father);

		if (roomId == 0) {
			roomId = createGonghuiRoom(father, true);
		}
		JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_ShowGonghuiInfo);
		// message.addProperty("type", EventType.Guo.toString());
		message.addProperty("name", gonghuiname);
		message.addProperty("name1", gonghuiname1);
		message.addProperty("name2", gonghuiname2);
		message.addProperty("name3", gonghuiname3);
		message.addProperty("name4", gonghuiname4);
		message.addProperty("name5", gonghuiname5);
		message.addProperty("name6", gonghuiname6);
		message.addProperty("ower", fatherName);
		message.addProperty("roomId", roomId);
		JsonMessageCenter.getInstance().sendMessage(message, user);
	}*/

	// 获取工会房间列表
	private List<RoomRecord> getGonghuiRoomList(User user) {
		List<RoomRecord> list = RoomManager.getInstance().getRoomList(1, user.getPrimaryKey());
		List<RoomRecord> roomRecordList = new ArrayList<RoomRecord>();

		if (list != null && list.size() > 0) {
			Map<Integer, AbstractRoom> roomMap = RoomManager.getInstance().getRoomMap();
			for (RoomRecord roomRecord : list) {
				if (!roomMap.containsKey(roomRecord.getRoomId())) {
					// System.out.println("该房间已不在内存中，修改记录状态，房间号=" + roomRecord.getRoomId());
					// 修改状态
					// 更新房间记录状态
					Entity entity = RoomManager.getInstance().getRoomRecordEntityByRoomId(roomRecord.getRoomId());
					if (entity != null) {
						entity.setProperty("gameStatus", 0);
						DBManager.getInstance().saveOrUpdate(entity);
					}
				} else {
					roomRecordList.add(roomRecord);
				}
			}
		}
		return roomRecordList;
	}

	private int getARoom(User father) {
		// 获取可用的房间号
		List<RoomRecord> list = getGonghuiRoomList(father);
		if (list.size() < 1) {
			return 0;
		}
		for (RoomRecord roomRecord : list) {
			AbstractRoom room = RoomManager.getInstance().getRoomById(roomRecord.getRoomId());
			if (!room.isFull()) {
				System.out.println(room.getId());
				return room.getId();
			}
		}
		return 0;
	}

	// 进入工会房间
	/*private void joinGonghuiRoom(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		System.out.println(user.getUsername() + "," + user.getPrimaryKey());
		Admin admin = AdminManager.getAdmin(user.getPrimaryKey());
		if (admin == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "你还没有加入工会!");
			return;
		}
		System.out.println("工会房间设置" + admin.getRoomSettings());
		String fatherName = admin.getFatherName();
		User father;
		if ("admin".equals(fatherName)) {
			father = user;
			System.out.println("自己的工会");
		} else {
			father = UserUtils.getUserByPrimaryKey(fatherName);
		}
		System.out.println("fatherName" + fatherName);
		System.out.println("====================进入工会房间");
		// 直接显示开房信息，不作任何操作（后续操作与createRoom时所调用的功能相同）
		// RoomSetting roomSetting = new RoomSetting();

		// if (!father.userCurrency().canSpend(CurrencyKind.Diamonds,
		// roomSetting.getPrice())) {
		// JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
		// } else {
		// // 从client端传递roomType过来，判断房间类型，进而创建房间
		// int roomType = serverMsg.getAsInt("roomType");
		// if (roomType == CardContants.GAMETYPE_SH) {
		// createShRoom(user, serverMsg, true);
		// }

		int roomId = getARoom(father);
		if (roomId == 0) {
			roomId = createGonghuiRoom(father, true);
		}
		AbstractRoom room = RoomManager.getInstance().getRoomById(roomId);
		if (room.getRoomType() == CardContants.GAMETYPE_SH) {
			com.card.game.Player player = new com.card.game.Player(user);
			if (room.getPlayerList().size() < 1) {
				SHRoom shRoom = (SHRoom) room;
				shRoom.changeZhuang(player.getUserId());
			}
			room.addPlayer(player);
		}
	}*/

	/**
	 * 创建工会房
	 * 
	 * @param user
	 * @param isAgency
	 * @return
	 */
	/*private int createGonghuiRoom(User user, boolean isAgency) {
		// int roomMode = serverMsg.getAsInt("roomMode");
		// boolean isAa = false;
		// // 息县房间设置
		// int gameNumber = serverMsg.getAsInt("gameNumber");
		// int userNum = serverMsg.getAsInt("usernum");
		// boolean hasHunzi = serverMsg.getAsBoolean("hasHunzi");
		// boolean zhuangJia = serverMsg.getAsBoolean("zhuang");
		// boolean noFeng = serverMsg.getAsBoolean("feng");
		// // boolean ma = serverMsg.getAsBoolean("ma");
		// int ma = serverMsg.getAsInt("maima");
		//
		// System.out.println("serverMsg" + gameNumber + userNum + hasHunzi + noFeng +
		// zhuangJia + ma);
		// 房间信息
		Admin admin = AdminManager.getAdmin(user.getPrimaryKey());
		String roomSettings = admin.getRoomSettings();
		String[] settings = roomSettings.split(",");
		RoomSetting roomSetting = new RoomSetting();

		roomSetting.setRoomMode(RoomMode.values()[Integer.parseInt(settings[0]) == 8 ? 0 : 1]);

		roomSetting.setDi(1);
		roomSetting.setRoomType(CardContants.GAMETYPE_SH);
		roomSetting.setAa(false);

		roomSetting.setUserNum(Integer.parseInt(settings[1]));
		roomSetting.setHasHunzi(Integer.parseInt(settings[2]) == 1);
		roomSetting.setZhuangJiadi(Integer.parseInt(settings[3]) == 1);
		roomSetting.setHaveFeng(Integer.parseInt(settings[4]) == 0);
		roomSetting.setMaima(Integer.parseInt(settings[5]));

		SHRoom room = new SHRoom(user.getPrimaryKey());
		room.setRoomSetting(roomSetting);
		RoomManager.getInstance().addRoom(room);
		room.startTime();
		GamePlayer play = new GamePlayer();
		List<GamePlayer> playerList = Lists.newArrayList();
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");

		playerList.add(play);
		entity.setProperty("isAgency", 1);

		// 获取数据，封装进recordroom对象
		// 房间号
		int roomId = room.getId();
		// 游戏状态
		int gameStatus = 1;
		// 加入集合，数据库存储

		playerList.add(play);
		playerList.add(play);
		playerList.add(play);
		Gson gson = new Gson();
		String jsonPlayerList = gson.toJson(playerList);
		Mj mj = new Mj();
		mj.setGameNumber(4);
		mj.setPlayerNumber(4);
		String jsonMj = gson.toJson(mj);

		entity.setProperty("roomId", roomId);
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_SH);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayerList);
		entity.setProperty("gameWay", jsonMj);
		DBManager.getInstance().saveOrUpdate(entity);
		return roomId;
	}*/

	// 代开房间列表
	private void RoomList(JsonMessage msg, ChannelHandlerContext ctx) {
		JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_Room_List);
		int gameStatus = msg.getAsInt("gameStatus");

		User user = (User) ctx.getAttachment();
		List<RoomRecord> list = RoomManager.getInstance().getRoomList(1, user.getPrimaryKey());
		List<RoomRecord> roomRecordList = new ArrayList<RoomRecord>();

		if (list != null && list.size() > 0) {
			Map<Integer, AbstractRoom> roomMap = RoomManager.getInstance().getRoomMap();
			for (RoomRecord roomRecord : list) {
				if (!roomMap.containsKey(roomRecord.getRoomId())) {
					System.out.println("该房间已不在内存中，修改记录状态，房间号=" + roomRecord.getRoomId());
					// 修改状态
					// 更新房间记录状态
					Entity entity = RoomManager.getInstance().getRoomRecordEntityByRoomId(roomRecord.getRoomId());
					if (entity != null) {
						entity.setProperty("gameStatus", 0);
						DBManager.getInstance().saveOrUpdate(entity);
					}
				} else {
					roomRecordList.add(roomRecord);
				}
			}
		}
		message.addProperty("roomRecordList", roomRecordList);
		JsonMessageCenter.getInstance().sendMessage(message, ctx);
	}

	// 历史代开房间记录列表
	private void HistoryRoomList(JsonMessage msg, ChannelHandlerContext ctx) {
		JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_HistoryRoom_List);
		int gameStatus = msg.getAsInt("gameStatus");
		User user = (User) ctx.getAttachment();
		List<RoomRecord> roomRecordList = RoomManager.getInstance().getRoomList(0, user.getPrimaryKey());
		message.addProperty("roomRecordList", roomRecordList);
		JsonMessageCenter.getInstance().sendMessage(message, ctx);
	}

	// 加入房间
	private void joinRoom(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		int type = serverMsg.getAsInt("roomType");
		int roomId = serverMsg.getAsInt("roomId");

		AbstractRoom room = RoomManager.getInstance().getRoomById(roomId);
		if (room == null
		// || room.getRoomType() != type
		) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "没有该房间，请重新输入！");
			return;
		}
		if (room instanceof IMatchRoom) {
			IMatchRoom matchRoom = (IMatchRoom) room;
			matchRoom.enterMatchRoom(user.getPrimaryKey());
			return;
		}
		if (room.isStartGame()
		// syl editor
		// && room.getRoomType() == CardContants.GAMETYPE_SH
		) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房间已经开始游戏");
			return;
		}
		if (room.isFull()) {
			if (room.getPlayerById(user.getPrimaryKey()) != null) {
				room.sendRoomInfo();
				return;
			}
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房间已满员！");
			return;
		}
		if (room.getRoomType() == CardContants.GAMETYPE_SH) {
			// Player player = new Player(user);
			com.card.game.Player player = new com.card.game.Player(user);
			if (room.getPlayerList().size() < 1) {
				SHRoom shRoom = (SHRoom) room;
				shRoom.changeZhuang(player.getUserId());
			}
			room.addPlayer(player);
		} else if (room.getRoomType() == CardContants.GAMETYPE_TGG) {
			ZjhPlayer player = new ZjhPlayer(user);
			room.addPlayer(player);
		} else if (room.getRoomType() == CardContants.GAMETYPE_Ddz) {
			DdzPlayer player = new DdzPlayer(user);
			room.addPlayer(player);
		} else if (room.getRoomType() == CardContants.GAMETYPE_Pdk) {
			PdkPlayer player = new PdkPlayer(user);
			room.addPlayer(player);
		} else if (room.getRoomType() == CardContants.GAMETYPE_Nn) {
			NnPlayer player = new NnPlayer(user);
			room.addPlayer(player);
		}
	}

	// 用户等待
	private void userReady(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		AbstractRoom room = user.getRoom();
		if (room == null || !(room.getState() == RoomState.Wait || room.getState() == RoomState.End)) {
			return;
		}
		BasePlayer player = room.getPlayerById(user.getPrimaryKey());
		if (player.getState() == UserState.Ready) {
			return;
		}
		player.setState(UserState.Ready);
		room.sendRoomInfo();
		if (room.getRoomType() == CardContants.GAMETYPE_SH && room.getPlayerList().size() == room.getMaxUserNum()
				&& room.allIsState(UserState.Ready)) {
			SHRoom shRoom = (SHRoom) room;
			shRoom.doJiabeiAction();
		} else if ((room.getRoomType() == CardContants.GAMETYPE_TGG || room.getRoomType() == CardContants.GAMETYPE_Ddz
				|| room.getRoomType() == CardContants.GAMETYPE_Pdk || room.getRoomType() == CardContants.GAMETYPE_Nn)
				&& room.getPlayerList().size() >= room.getMaxUserNum() && room.allIsState(UserState.Ready)) {
			room.startGame();
		}
	}

	// 创建麻将房
	private void createShRoom(User user, JsonMessage serverMsg, boolean isAgency) {
		int roomMode = serverMsg.getAsInt("roomMode");
		boolean isAa = false;
		// 息县房间设置
		int gameNumber = serverMsg.getAsInt("gameNumber");
		int userNum = serverMsg.getAsInt("usernum");
		boolean hasHunzi = serverMsg.getAsBoolean("hasHunzi");
		boolean zhuangJia = serverMsg.getAsBoolean("zhuang");
		boolean noFeng = serverMsg.getAsBoolean("feng");
		// boolean ma = serverMsg.getAsBoolean("ma");
		int ma = serverMsg.getAsInt("maima");
		//
		System.out.println("serverMsg" + roomMode + gameNumber + userNum + hasHunzi + noFeng + zhuangJia + ma+"ceshi123");
		// 房间信息
		RoomSetting roomSetting = new RoomSetting();
		roomSetting.setRoomMode(RoomMode.values()[roomMode]);

		roomSetting.setDi(1);
		roomSetting.setRoomType(CardContants.GAMETYPE_SH);
		roomSetting.setAa(false);

		roomSetting.setUserNum(userNum);
		roomSetting.setHasHunzi(hasHunzi);
		roomSetting.setZhuangJiadi(zhuangJia);
		roomSetting.setHaveFeng(!noFeng);
		roomSetting.setMaima(ma);

		roomSetting.setHasPao(false);

		if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
			return;
		}

		SHRoom room = new SHRoom(user.getPrimaryKey());
		// if (isAgency) {
		// room.changeZhuang();
		// }
		room.setRoomSetting(roomSetting);
		RoomManager.getInstance().addRoom(room);
		room.startTime();
		GamePlayer play = new GamePlayer();
		List<GamePlayer> playerList = Lists.newArrayList();
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");
		if (!isAgency) {
			Player player = new Player(user);
			player.setState(UserState.Ready);
			room.addPlayer(player);
			GamePlayer pl = new GamePlayer();
			pl.setHeadPicUrl(player.img);
			pl.setNickName(player.nickName);
			pl.setUserId(user.getPrimaryKey());
			playerList.add(pl);
			entity.setProperty("isAgency", 0);
		} else {
			playerList.add(play);
			entity.setProperty("isAgency", 1);
		}

		// 获取数据，封装进recordroom对象
		// 房间号
		int roomId = room.getId();
		// 游戏状态
		int gameStatus = 1;
		// 加入集合，数据库存储

		playerList.add(play);
		playerList.add(play);
		playerList.add(play);
		Gson gson = new Gson();
		String jsonPlayerList = gson.toJson(playerList);
		Mj mj = new Mj();
		// mj.setBottom(di);
		// mj.setFlower(hua);
		mj.setGameNumber(gameNumber);
		mj.setPlayerNumber(gameNumber);
		// mj.setPlayWay(isZimoFanFan == true ? 1 : 0);
		String jsonMj = gson.toJson(mj);

		entity.setProperty("roomId", roomId);
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_SH);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayerList);
		entity.setProperty("gameWay", jsonMj);
		DBManager.getInstance().saveOrUpdate(entity);
	}

	// 炸金花房
	private void createTGGRoom(User user, JsonMessage serverMsg, boolean isAgency) {
		int roomMode = serverMsg.getAsInt("roomMode");
		int gameNumber = serverMsg.getAsInt("gameNumber");
		int menNum = serverMsg.getAsInt("menNum");
		int userNum = serverMsg.getAsInt("userNum");
		int maxLunNum = serverMsg.getAsInt("maxLunNum");
		boolean isAa = serverMsg.getAsInt("isAa") == 1;
		// int cardNumber = serverMsg.getAsInt("cardNumber");
		// int wheelNumber = serverMsg.getAsInt("wheelNumber");

		RoomSetting roomSetting = new RoomSetting();
		roomSetting.setRoomMode(RoomMode.values()[roomMode]);
		roomSetting.setBetLimit(10);
		roomSetting.setRoomType(CardContants.GAMETYPE_TGG);
		roomSetting.setAa(isAa);
		roomSetting.setUserNum(userNum);
		roomSetting.setMenNum(menNum);
		roomSetting.setMaxLunNum(maxLunNum);
		if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
			return;
		}
		int roomId = 0;
		List<GamePlayer> playerList = Lists.newArrayList();
		GamePlayer play = new GamePlayer();
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");
		// 非代开
		if (!isAgency) {
			ZjhPlayer player = new ZjhPlayer(user);
			TggRoom room = new TggRoom(player, roomSetting);
			RoomManager.getInstance().addRoom(room);
			room.startTime();
			roomId = room.getId();
			GamePlayer pl = new GamePlayer();
			pl.setHeadPicUrl(player.img);
			pl.setNickName(player.nickName);
			pl.setUserId(user.getPrimaryKey());
			playerList.add(pl);
			entity.setProperty("isAgency", 0);
		} else {
			TggRoom room = new TggRoom(user.getPrimaryKey(), roomSetting);
			RoomManager.getInstance().addRoom(room);
			room.startTime();
			roomId = room.getId();
			entity.setProperty("isAgency", 1);
			playerList.add(play);
		}
		// 获取数据，封装进recordroom对象
		// 房间号
		// 创建时间
		// 游戏状态
		int gameStatus = 1;
		// 加入集合，数据库存储

		// play.setNickName("百度");
		// play.setUserId(123);
		// play.setHeadPicUrl("https://www.baidu.com/img/bd_logo1.png");
		// GamePlayer play2 = new GamePlayer();
		// play2.setNickName("谷歌");
		// play2.setUserId(124);
		// play2.setHeadPicUrl("https://www.baidu.com/img/bd_logo1.png");
		// GamePlayer play3 = new GamePlayer();
		// play3.setNickName("搜狗");
		// play3.setUserId(133);
		// play3.setHeadPicUrl("https://www.baidu.com/img/bd_logo1.png");
		// GamePlayer play4 = new GamePlayer();
		// play4.setNickName("搜狐");
		// play4.setUserId(123);
		// play4.setHeadPicUrl("https://www.baidu.com/img/bd_logo1.png");

		for (int i = 0; i < userNum - 1; i++) {
			playerList.add(play);
		}
		Gson gson = new Gson();
		String jsonPlayer = gson.toJson(playerList);
		Zjh zjh = new Zjh();
		zjh.setGameNumber(gameNumber);
		zjh.setPlayerNumber(userNum);
		zjh.setWheelNumber(maxLunNum);
		zjh.setCardNumber(menNum);
		String jsonZjh = gson.toJson(zjh);

		entity.setProperty("roomId", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_TGG);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayer);
		entity.setProperty("gameWay", jsonZjh);
		DBManager.getInstance().saveOrUpdate(entity);
		System.out.println(entity);
	}

	// 斗地主房间
	private void createDdzRoom(User user, JsonMessage serverMsg, boolean isAgency) {
		System.out.println("================开房间斗地主");
		int roomMode = serverMsg.getAsInt("roomMode");
		boolean isAa = serverMsg.getAsInt("isAa") == 1;
		int gameNumber = serverMsg.getAsInt("gameNumber");
		// int zhaDanTop = serverMsg.getAsInt("zhaDanTop");
		RoomSetting roomSetting = new RoomSetting();
		roomSetting.setRoomMode(RoomMode.values()[roomMode]);
		// roomSetting.setZhaDanTop(zhaDanTop);
		roomSetting.setRoomType(CardContants.GAMETYPE_Ddz);
		roomSetting.setAa(isAa);
		if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
			return;
		}
		List<GamePlayer> playerList = Lists.newArrayList();
		GamePlayer play = new GamePlayer();
		DdzRoom room = new DdzRoom(user.getPrimaryKey());
		room.setRoomSetting(roomSetting);
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");
		if (!isAgency) {
			DdzPlayer player = new DdzPlayer(user);
			room.addPlayer(player);
			GamePlayer pl = new GamePlayer();
			pl.setHeadPicUrl(player.img);
			pl.setNickName(player.nickName);
			pl.setUserId(user.getPrimaryKey());
			playerList.add(pl);
			entity.setProperty("isAgency", 0);
		} else {
			playerList.add(play);
			entity.setProperty("isAgency", 1);

		}
		RoomManager.getInstance().addRoom(room);
		room.startTime();
		// 操作数据库，每次邀请几个玩家，何时退出，都需要放到数据库中
		// 获取数据，封装进recordroom对象
		// 获取数据，封装进recordroom对象
		// 房间号
		int roomId = room.getId();
		// 创建时间
		// 游戏状态
		int gameStatus = 1;
		// 加入集合，数据库存储

		playerList.add(play);
		playerList.add(play);
		// 改
		Gson gson = new Gson();
		String jsonPlayer = gson.toJson(playerList);
		Ddz ddz = new Ddz();
		ddz.setGameNumber(gameNumber);
		ddz.setPlayerNumber(3);
		String jsonDdz = gson.toJson(ddz);

		entity.setProperty("roomId", roomId);
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_Ddz);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayer);
		entity.setProperty("gameWay", jsonDdz);
		DBManager.getInstance().saveOrUpdate(entity);

	}

	/**
	 * 创建跑得快房间
	 */
	private void createPdkRoom(User user, JsonMessage serverMsg, boolean isAgency) {
		int roomMode = serverMsg.getAsInt("roomMode");
		boolean isAa = serverMsg.getAsInt("isAa") == 1;
		// int zhaDanTop = serverMsg.getAsInt("zhaDanTop");
		int gameNumber = serverMsg.getAsInt("gameNumber");
		RoomSetting roomSetting = new RoomSetting();
		roomSetting.setRoomMode(RoomMode.values()[roomMode]);
		// roomSetting.setZhaDanTop(zhaDanTop);
		roomSetting.setRoomType(CardContants.GAMETYPE_Pdk);
		roomSetting.setAa(isAa);

		if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
			return;
		}
		List<GamePlayer> playerList = Lists.newArrayList();
		GamePlayer play = new GamePlayer();
		PdkRoom room = new PdkRoom(user.getPrimaryKey());
		room.setRoomSetting(roomSetting);
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");
		if (!isAgency) {
			PdkPlayer player = new PdkPlayer(user);
			room.addPlayer(player);
			GamePlayer pl = new GamePlayer();
			pl.setHeadPicUrl(player.img);
			pl.setNickName(player.nickName);
			pl.setUserId(user.getPrimaryKey());
			playerList.add(pl);
			entity.setProperty("isAgency", 0);
		} else {
			playerList.add(play);
			entity.setProperty("isAgency", 1);
		}
		RoomManager.getInstance().addRoom(room);
		room.startTime();
		int roomId = room.getId();
		int gameStatus = 1;
		playerList.add(play);
		playerList.add(play);
		// 改
		Gson gson = new Gson();
		String jsonPlayer = gson.toJson(playerList);
		Pdk pdk = new Pdk();
		pdk.setGameNumber(gameNumber);
		pdk.setPlayerNumber(3);
		String jsonDdz = gson.toJson(pdk);

		entity.setProperty("roomId", roomId);
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_Pdk);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayer);
		entity.setProperty("gameWay", jsonDdz);
		DBManager.getInstance().saveOrUpdate(entity);
	}

	// 牛牛房间
	private void createNnRoom(User user, JsonMessage serverMsg, boolean isAgency) {
		int roomMode = serverMsg.getAsInt("roomMode");
		int gameNumber = serverMsg.getAsInt("gameNumber");
		int userNum = serverMsg.getAsInt("userNum");
		int nnType = serverMsg.getAsInt("nnType");
		int beiTop = serverMsg.getAsInt("beiTop");
		boolean isAa = serverMsg.getAsInt("isAa") == 1;

		// int declarer = serverMsg.getAsInt("declarer");
		// int sealRoof = serverMsg.getAsInt("sealRoof");

		RoomSetting roomSetting = new RoomSetting();
		roomSetting.setRoomMode(RoomMode.values()[roomMode]);
		roomSetting.setRoomType(CardContants.GAMETYPE_Nn);
		roomSetting.setUserNum(userNum);
		roomSetting.setBeiTop(beiTop);
		roomSetting.setNnType(nnType);
		roomSetting.setAa(isAa);

		if (!user.userCurrency().canSpend(CurrencyKind.Diamonds, roomSetting.getPrice())) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "房卡不足,无法创建房间");
			return;
		}
		// 非代开房间
		int roomId = 0;
		List<GamePlayer> playerList = Lists.newArrayList();
		GamePlayer play = new GamePlayer();
		Entity entity = new Entity(RoomManager.R_Table, PrimaryKey.getIntPrimaryKey("roomId") + "");
		if (!isAgency) {
			NnPlayer player = new NnPlayer(user);
			NnRoom room = new NnRoom(player, roomSetting);
			RoomManager.getInstance().addRoom(room);
			room.startTime();
			roomId = room.getId();
			GamePlayer pl = new GamePlayer();
			pl.setHeadPicUrl(player.img);
			pl.setNickName(player.nickName);
			pl.setUserId(user.getPrimaryKey());
			playerList.add(pl);
			entity.setProperty("isAgency", 0);
		} else {
			NnRoom room = new NnRoom(user.getPrimaryKey(), roomSetting);
			RoomManager.getInstance().addRoom(room);
			room.startTime();
			roomId = room.getId();
			playerList.add(play);
			entity.setProperty("isAgency", 1);
		}

		// 获取数据，封装进recordroom对象
		// 房间号
		// 游戏状态
		int gameStatus = 1;
		// 加入集合，数据库存储

		for (int i = 0; i < userNum - 1; i++) {
			playerList.add(play);
		}

		Gson gson = new Gson();
		String jsonPlayer = gson.toJson(playerList);

		Nn nn = new Nn();
		nn.setGameNumber(gameNumber);
		nn.setPlayerNumber(userNum);
		nn.setDeclarer(nnType);
		nn.setSealRoof(beiTop);
		String jsonNn = gson.toJson(nn);

		entity.setProperty("roomId", roomId);
		entity.setProperty("roomNumber", roomId);
		entity.setProperty("createUserId", user.getPrimaryKey());
		entity.setProperty("gameStatus", gameStatus);
		entity.setProperty("gameType", CardContants.GAMETYPE_Nn);
		entity.setProperty("createTime", DateUtils.getCurrentTime());
		entity.setProperty("gamePlayerList", jsonPlayer);
		entity.setProperty("gameWay", jsonNn);
		DBManager.getInstance().saveOrUpdate(entity);
	}

	private void dxRoomDisband(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();

		AbstractRoom room = user.getRoom();
		if (room == null) {
			// JsonMessageCenter.getInstance().sendEorrorMessage(user, "解散房间不存在");
			return;
		} else {
			room.disbandRoom();
		}
	}
	// private void disbandRoom(JsonMessage serverMsg, ChannelHandlerContext
	// ctx) {
	// User user = (User)ctx.getAttachment();
	//
	// AbstractRoom room = user.getRoom();
	// if(room == null) {
	// JsonMessageCenter.getInstance().sendEorrorMessage(user, "解散房间不存在");
	// return;
	// }
	// if(room.isOwner(user.getPrimaryKey())) {
	// room.disbandRoom();
	// }
	// }

	/**
	 * 解散代开房间
	 */
	private void disbandAgencyCreateRoom(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		int roomId = serverMsg.getAsInt("roomId");
		AbstractRoom room = user.getRoom(roomId);
		if (room == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "解散房间不存在");
			return;
		}
		if (!room.isStartGame() && room.getState() == RoomState.Wait) {
			if (StringUtil.equals(user.getPrimaryKey(), room.getOwnerId())) {
				room.setFirstDisandRequestId(user.getPrimaryKey());
				room.disbandAgencyRoom();
				JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_DisbandAgencyCreateRoom);
				JsonMessageCenter.getInstance().sendMessage(message, ctx);
			} else {
				room.leaveRoom(user.getPrimaryKey());
				JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_DisbandAgencyCreateRoom);
				JsonMessageCenter.getInstance().sendMessage(message, ctx);
			}
			// 更新房间记录状态
			Entity entity = RoomManager.getInstance().getRoomRecordEntityByRoomId(roomId);
			if (entity != null) {
				entity.setProperty("gameStatus", 0);
				DBManager.getInstance().saveOrUpdate(entity);
			}
			return;
		} else {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "玩家已开始游戏，禁止解散");
			return;
		}

		// // 就你一个人
		// if (room.getPlayerList().size() == 1
		// // || !room.isStartGame()
		// ) {
		// // 讲房间的控制权交给了仅剩的一个人
		// room.setFirstDisandRequestId(user.getPrimaryKey());
		// room.disbandAgencyRoom();
		// //更新房间记录状态
		// Entity entity=RoomManager.getInstance().getRoomRecordEntityByRoomId(roomId);
		// if(entity!=null){
		// entity.setProperty("gameStatus", 0);
		// DBManager.getInstance().saveOrUpdate(entity);
		// }
		// return;
		// }
		// BasePlayer player = room.getPlayerById(user.getPrimaryKey());
		// if (player == null) {
		// //更新房间记录状态
		// Entity entity=RoomManager.getInstance().getRoomRecordEntityByRoomId(roomId);
		// if(entity!=null){
		// entity.setProperty("gameStatus", 0);
		// DBManager.getInstance().saveOrUpdate(entity);
		// }
		// return;
		// }
		// room.setFirstDisandRequestId(player.getUserId());
		// room.setState(RoomState.DisbandRequest);
		// player.getPlayerInfo().setDisbandReply(1);
		//
		// room.sendDisandRoomRequest();
		// JsonMessage message =
		// JsonMessage.createMessage(MessageComm.S2C_DisbandAgencyCreateRoom);
		// JsonMessageCenter.getInstance().sendMessage(message, ctx);
		// //更新房间记录状态
		// Entity entity=RoomManager.getInstance().getRoomRecordEntityByRoomId(roomId);
		// if(entity!=null){
		// entity.setProperty("gameStatus", 0);
		// DBManager.getInstance().saveOrUpdate(entity);
		// }
	}

	// 解散房间请求
	private void disbandRoomRequest(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		AbstractRoom room = user.getRoom();
		if (room == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "解散房间不存在");
			return;
		}
		// if(room.getRoomType() == CardContants.GAMETYPE_TGG) {
		// //腿刚刚可以直接解散房间
		// if(room.isOwner(user.getPrimaryKey())) {
		// room.disbandRoom();
		// return;
		// }
		// JsonMessageCenter.getInstance().sendEorrorMessage(user, "您没有权限解散房间");
		// return;
		// }
		if (!room.isStartGame() && room.getState() == RoomState.Wait) {
			if (StringUtil.equals(user.getPrimaryKey(), room.getOwnerId())) {
				room.setFirstDisandRequestId(user.getPrimaryKey());
				room.disbandRoom();
			} else {
				room.leaveRoom(user.getPrimaryKey());
				JsonMessage message = JsonMessage.createMessage(MessageComm.S2C_LeaveRoom);
				JsonMessageCenter.getInstance().sendMessage(message, ctx);
			}
			return;
		}

		// 就你一个人
		if (room.getPlayerList().size() == 1
		// || !room.isStartGame()
		) {
			// 讲房间的控制权交给了仅剩的一个人
			room.setFirstDisandRequestId(user.getPrimaryKey());
			room.disbandRoom();
			return;
		}
		BasePlayer player = room.getPlayerById(user.getPrimaryKey());
		if (player == null) {
			return;
		}
		room.setFirstDisandRequestId(player.getUserId());
		room.setState(RoomState.DisbandRequest);
		player.getPlayerInfo().setDisbandReply(1);

		room.sendDisandRoomRequest();
	}

	// 房间解散后向client传递的信息（同意或拒绝）
	private void disbandRoomReply(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		User user = (User) ctx.getAttachment();
		AbstractRoom room = user.getRoom();
		if (room == null) {
			JsonMessageCenter.getInstance().sendEorrorMessage(user, "解散房间不存在");
			return;
		}
		int reply = serverMsg.getAsInt("reply");
		BasePlayer player = room.getPlayerById(user.getPrimaryKey());
		if (player == null) {
			return;
		}
		player.getPlayerInfo().setDisbandReply(reply);
		if (reply == 2) {
			int noNum = 0;
			for (BasePlayer p : room.getPlayerList()) {
				DisbandReply temp = p.getPlayerInfo().getDisbandReply();
				if (temp.getDisbandReply() == 2
				// || !p.isOnline()
				) {
					noNum++;
				}
			}
			if (noNum >= 1) {
				// if (noNum >= 2 || room.getMaxUserNum() == 2) {
				// 拒绝
				JsonMessage message = new JsonMessage(MessageComm.S2C_RoomDisbandReply);
				message.addProperty("userId", user.getPrimaryKey());
				message.addProperty("reply", reply);
				room.broadcast(message);
				room.clearDisandReply();
				room.setState(room.getLastState());
				return;
			}
		}
		room.checkDisandReply();
	}

	private void startTgg(JsonMessage serverMsg, ChannelHandlerContext ctx) {
		// User user = (User)ctx.getAttachment();
		// AbstractRoom room = user.getRoom();
		// if(room == null) {
		// JsonMessageCenter.getInstance().sendEorrorMessage(user, "房间不存在");
		// return;
		// }
		// if(room.getRoomType() != CardContants.GAMETYPE_TGG) {
		// JsonMessageCenter.getInstance().sendEorrorMessage(user,
		// "只有推杠杠房间才能手动开始");
		// return;
		// }
		// TggRoom tggRoom = (TggRoom)room;
		// if(!tggRoom.isCanStart) {
		// JsonMessageCenter.getInstance().sendEorrorMessage(user,
		// "房间人数不满足要求!");
		// return;
		// }
		// tggRoom.startGame();
	}

}
